package iip

import (
    "context"
    "time"

    "iip/iip/iip_type"
    "iip/iip/model"
    "rpc/tms"
)


func (s *IIP) QueryVehicleDispatchOrder(ctx context.Context, in *tms.ReqQueryVehicleDispatchOrder) (*tms.RspQueryVehicleDispatchOrder, error) {
    rsp := &tms.RspQueryVehicleDispatchOrder{}
    return rsp, nil
}


func (s *IIP) UploadWeightRecord(ctx context.Context, in *tms.ReqUploadWeightRecord) (*tms.RspUploadWeightRecord, error) {
    rsp := &tms.RspUploadWeightRecord{}
    name := in.WeighbridgeName
    s.logger.Info("称重记录")
    s.logger.Info("  |-磅房编号", name)




    rec := &model.WeightRecord{}
    rec.ID = s.idgen.NextID()
    rec.WeighbridgeName = in.WeighbridgeName
    rec.SerailNo = ""
    rec.Type = iip_type.WeightTypeSales1
    rec.Duration = int(time.Duration(in.Duration) / time.Second)
    rec.LicensePlate = in.MainLicensePlate

    rec.Weight = int(in.Weight)

    if err := s.gorm().Create(rec).Error; err != nil {
        s.logger.Error(err)
        rsp.ErrMsg = err.Error()
        rsp.ErrCode = iip_type.ErrCodeDB
        return rsp, nil
    }

    return rsp, nil
}


func (s *IIP) Ping(ctx context.Context, in *tms.ReqPing) (*tms.RspPing, error) {
    rsp := &tms.RspPing{}
    rsp.Pong = "PONG"
    return rsp, nil
}
